from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-06-09 14:02:25.615575
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 09, Jun, 2022
Time: 14:02:31
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.5082
Nobs: 682.000 HQIC: -49.8742
Log likelihood: 8466.47 FPE: 1.73600e-22
AIC: -50.1053 Det(Omega_mle): 1.52284e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.307937 0.059192 5.202 0.000
L1.Burgenland 0.105491 0.038324 2.753 0.006
L1.Kärnten -0.109137 0.020209 -5.400 0.000
L1.Niederösterreich 0.200771 0.079964 2.511 0.012
L1.Oberösterreich 0.116862 0.078730 1.484 0.138
L1.Salzburg 0.255554 0.040876 6.252 0.000
L1.Steiermark 0.046382 0.053535 0.866 0.386
L1.Tirol 0.107176 0.043274 2.477 0.013
L1.Vorarlberg -0.058631 0.037759 -1.553 0.120
L1.Wien 0.032284 0.069880 0.462 0.644
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.041503 0.125218 0.331 0.740
L1.Burgenland -0.034107 0.081074 -0.421 0.674
L1.Kärnten 0.040018 0.042752 0.936 0.349
L1.Niederösterreich -0.181777 0.169162 -1.075 0.283
L1.Oberösterreich 0.440408 0.166552 2.644 0.008
L1.Salzburg 0.285179 0.086472 3.298 0.001
L1.Steiermark 0.108255 0.113252 0.956 0.339
L1.Tirol 0.315257 0.091545 3.444 0.001
L1.Vorarlberg 0.025795 0.079878 0.323 0.747
L1.Wien -0.032956 0.147829 -0.223 0.824
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187149 0.030396 6.157 0.000
L1.Burgenland 0.088798 0.019680 4.512 0.000
L1.Kärnten -0.007661 0.010378 -0.738 0.460
L1.Niederösterreich 0.258364 0.041063 6.292 0.000
L1.Oberösterreich 0.143393 0.040430 3.547 0.000
L1.Salzburg 0.045302 0.020991 2.158 0.031
L1.Steiermark 0.024200 0.027491 0.880 0.379
L1.Tirol 0.088645 0.022222 3.989 0.000
L1.Vorarlberg 0.056839 0.019390 2.931 0.003
L1.Wien 0.116102 0.035885 3.235 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.110400 0.030616 3.606 0.000
L1.Burgenland 0.044669 0.019823 2.253 0.024
L1.Kärnten -0.013994 0.010453 -1.339 0.181
L1.Niederösterreich 0.186506 0.041361 4.509 0.000
L1.Oberösterreich 0.314246 0.040723 7.717 0.000
L1.Salzburg 0.103593 0.021143 4.900 0.000
L1.Steiermark 0.108478 0.027691 3.917 0.000
L1.Tirol 0.101219 0.022383 4.522 0.000
L1.Vorarlberg 0.066950 0.019531 3.428 0.001
L1.Wien -0.022975 0.036145 -0.636 0.525
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.122301 0.056465 2.166 0.030
L1.Burgenland -0.047623 0.036559 -1.303 0.193
L1.Kärnten -0.045989 0.019278 -2.386 0.017
L1.Niederösterreich 0.146853 0.076280 1.925 0.054
L1.Oberösterreich 0.150819 0.075103 2.008 0.045
L1.Salzburg 0.282388 0.038993 7.242 0.000
L1.Steiermark 0.053163 0.051069 1.041 0.298
L1.Tirol 0.167506 0.041280 4.058 0.000
L1.Vorarlberg 0.097112 0.036020 2.696 0.007
L1.Wien 0.075941 0.066661 1.139 0.255
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.061581 0.044636 1.380 0.168
L1.Burgenland 0.031948 0.028900 1.105 0.269
L1.Kärnten 0.051333 0.015239 3.368 0.001
L1.Niederösterreich 0.207158 0.060300 3.435 0.001
L1.Oberösterreich 0.304118 0.059369 5.122 0.000
L1.Salzburg 0.043382 0.030824 1.407 0.159
L1.Steiermark 0.007545 0.040370 0.187 0.852
L1.Tirol 0.136704 0.032632 4.189 0.000
L1.Vorarlberg 0.073937 0.028474 2.597 0.009
L1.Wien 0.082835 0.052695 1.572 0.116
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.171008 0.053541 3.194 0.001
L1.Burgenland 0.001153 0.034666 0.033 0.973
L1.Kärnten -0.064184 0.018280 -3.511 0.000
L1.Niederösterreich -0.090203 0.072330 -1.247 0.212
L1.Oberösterreich 0.199536 0.071214 2.802 0.005
L1.Salzburg 0.055057 0.036974 1.489 0.136
L1.Steiermark 0.241272 0.048424 4.982 0.000
L1.Tirol 0.499917 0.039143 12.772 0.000
L1.Vorarlberg 0.053688 0.034154 1.572 0.116
L1.Wien -0.064822 0.063209 -1.026 0.305
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.154858 0.060346 2.566 0.010
L1.Burgenland -0.007461 0.039071 -0.191 0.849
L1.Kärnten 0.062070 0.020603 3.013 0.003
L1.Niederösterreich 0.192670 0.081523 2.363 0.018
L1.Oberösterreich -0.070276 0.080265 -0.876 0.381
L1.Salzburg 0.208306 0.041673 4.999 0.000
L1.Steiermark 0.135526 0.054579 2.483 0.013
L1.Tirol 0.069002 0.044118 1.564 0.118
L1.Vorarlberg 0.133434 0.038495 3.466 0.001
L1.Wien 0.124286 0.071242 1.745 0.081
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.374664 0.035186 10.648 0.000
L1.Burgenland 0.000569 0.022782 0.025 0.980
L1.Kärnten -0.022570 0.012013 -1.879 0.060
L1.Niederösterreich 0.216325 0.047535 4.551 0.000
L1.Oberösterreich 0.214072 0.046801 4.574 0.000
L1.Salzburg 0.042340 0.024299 1.742 0.081
L1.Steiermark -0.018591 0.031824 -0.584 0.559
L1.Tirol 0.101923 0.025724 3.962 0.000
L1.Vorarlberg 0.064526 0.022446 2.875 0.004
L1.Wien 0.028681 0.041540 0.690 0.490
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037671 0.126432 0.183845 0.148638 0.107235 0.090190 0.047786 0.212714
Kärnten 0.037671 1.000000 -0.018022 0.133997 0.053338 0.092073 0.439369 -0.057130 0.093595
Niederösterreich 0.126432 -0.018022 1.000000 0.330963 0.136459 0.289524 0.082479 0.169258 0.309381
Oberösterreich 0.183845 0.133997 0.330963 1.000000 0.224257 0.316835 0.169246 0.154230 0.262238
Salzburg 0.148638 0.053338 0.136459 0.224257 1.000000 0.134143 0.106115 0.126077 0.132963
Steiermark 0.107235 0.092073 0.289524 0.316835 0.134143 1.000000 0.141136 0.119244 0.063461
Tirol 0.090190 0.439369 0.082479 0.169246 0.106115 0.141136 1.000000 0.093476 0.145183
Vorarlberg 0.047786 -0.057130 0.169258 0.154230 0.126077 0.119244 0.093476 1.000000 0.006849
Wien 0.212714 0.093595 0.309381 0.262238 0.132963 0.063461 0.145183 0.006849 1.000000